package com.yyw.bug;

import java.io.FileReader;
import java.io.IOException;

import au.com.bytecode.opencsv.CSVReader;

import com.yyw.bug.common.FileUtil;

public class CSV {

	private static final String fileFrom = "D:/wechat.csv";
	private static final String fileTo = "D:/wechat.txt";

	public static void main(String[] args) {
		CSVReader csvReader = null;
		try {
			csvReader = new CSVReader(new FileReader(fileFrom));

			String[] csvRow = null;
			String SQL = "";
			while ((csvRow = csvReader.readNext()) != null) {
				String wechatOrder = csvRow[0];//第三方订单
				String yywOrder = csvRow[1];//药网订单
				double amount = new Double(csvRow[2]);//金额
				
				//SQL 具体情况而定
				String upteteUSql = "UPDATE ecord_shoporder SET PayStatus =1,HadPay ="
						+ amount
						+ ",NetMode=46,BankCode=605,OutPayNumber = '"
						+ wechatOrder
						+ "',PayTime = now() WHERE OrderId = '"
						+ yywOrder + "';\n";
				String insertSql = "INSERT INTO ecord_ordernetpayrecord(OrderId,PayType,PayBank,HadPay, PayTime,OutPayNumber,BankCode,Status, AddTime) VALUES('"
						+ yywOrder
						+ "',1,46,"
						+ amount
						+ ", now(),'"
						+ wechatOrder
						+ "',605,0,now());\n\n";
				SQL += upteteUSql + insertSql;
			}
			
			FileUtil.writeFile(fileTo, SQL);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
